<template>
  <div class="homecontainer">
    <!--banner-->
    <van-image :src="bannerimg" class="bannerimg" height="200" width="100%" fit="cover" />
    <!--根据名字去判断-->
    <ul class="home_ul clearfix1">
      <li
        v-for="item in menu"
        :key="item.id"
        class="home_li"
        @click="routeToName(item.path,item.id)"
      >
        <div v-if="item.path=='/monitorIndex'" class="ssjk">
          <img :src="item.icon" class="home_icon" width="30" height="38" />
          <p class="title">{{item.name}}</p>
        </div>
        <div v-if="item.path=='/warnMessage'" class="bjxx">
          <img :src="item.icon" class="home_icon" width="40" height="38" />
          <p class="title">{{item.name}}</p>
        </div>
        <div v-if="item.path=='/communicateIndex'" class="ssdj">
          <img :src="item.icon" class="home_icon" width="25" height="40" />
          <p class="title">{{item.name}}</p>
        </div>
        <div v-if="item.path=='/attendanceIndex'" class="kqdk">
          <img :src="item.icon" class="home_icon" width="38" height="40" />
          <p class="title">{{item.name}}</p>
        </div>
        <div v-if="item.path=='/checkIndex'" class="khgl">
          <img :src="item.icon" class="home_icon" width="34" height="35" />
          <p class="title">{{item.name}}</p>
        </div>
        <div v-if="item.path=='/approveIndex'" class="spgl">
          <img :src="item.icon" class="home_icon" width="35" height="38" />
          <p class="title">{{item.name}}</p>
        </div>
        <div v-if="item.path=='/attendancecheck'" class="kqxc">
          <img :src="item.icon" class="home_icon" width="38" height="43" />
          <p class="title">{{item.name}}</p>
        </div>
        <div v-if="item.path=='/attendanceScavenging'" class="ljqy">
          <img :src="item.icon" class="home_icon" width="36" height="34" />
          <p class="title">{{item.name}}</p>
        </div>
      </li>
    </ul>
    <div>
      <!-- <p>当前经度：{{currentLng}}</p>
      <p>当前帷度：{{currentLat}}</p>-->
    </div>
  </div>
</template>
<script>
import { mapState, mapMutations } from "vuex";
export default {
  name: "HelloWorld",
  data() {
    return {
      params: {},
      bannerimg: require("../../../static/image/banner.png"),
      menu: [],
      currentLng: "", //当前经度
      currentLat: "", //当前纬度
      creditAddress: "" //当前位置
    };
  },
  computed: {
    ...mapState({
      token: state => state.Authorization,
      role_id: state => state.userData.role_id,
      id: state => state.userData.id,
      name: state => state.userData.name,
      project_company_id: state => state.userData.project_company_id,
      project_id: state => state.userData.project_company_id
    })
  },
  mounted() {
    
  },
  created() {
    this.home();
  },

  methods: {
    ...mapMutations(["changemenuid"]),
    //获取首页数据
    home() {
      this.$toast.loading({
        mask: true,
        message: "加载中..."
      });
      this.params = {
        type: 2,
        parent_id: 1,
        role_id: this.role_id,
        token: this.token
      };
      this.$http
        .get(`${this.$basePath}?service=App.Account.GetAuthMenuList`, {
          params: this.params
        })
        .then(res => {
          if (res.ret == 200) {
            this.$toast.clear();
            this.menu = res.data;
          } else {
            this.$toast({ message: res.msg });
          }
        });
    },
    routeToName(path, id) {
      this.changemenuid({
        muneid: id
      });
      switch (path) {
        case "/attendanceIndex":
          this.$router.push({
            //核心语句
            path: path //跳转的路径
          });
          break;
          
           case "/communicateIndex":
          this.$router.push({
            //核心语句
            path: path
          });
          break;
        case "/checkIndex":
          this.$router.push({
            //核心语句
            path: path
          });
          break;
        case "/approveIndex":
          this.$router.push({
            //核心语句
            path: path //跳转的路径
          });
          break;
        case "/warnMessage":
          this.$router.push({
            //核心语句
            path: path //跳转的路径
          });
          break;
        case "/monitorIndex":
          this.$router.push({
            //核心语句
            path: path //跳转的路径
          });
          break;
        case "/attendancecheck":
          this.$router.push({
            //核心语句
            path: path //跳转的路径
          });
          break;
        case "/attendanceScavenging":
          this.$router.push({
            //核心语句
            path: path //跳转的路径
          });
          break;

        default:
          this.$toast({
            message: "功能暂未开发"
          });
          break;
      }
    }
  }
};
</script>
<style lang="less" scoped>
@import "../../assets/css/home";
</style>